home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-26 | 2.1 KB | 121 lines | [TEXT/MMCC] |
- #include "SortPicts.h"
-
- Boolean SortPicts::PrepareGWorld( ConstStr255Param pictName)
- {
- if( !LoadPicture( pictName))
- return false;
-
- if( !MakeGWorld())
- {
- ReleaseResource( (Handle)sortPict);
- return false;
- }
-
- if( !AllocSortData())
- {
- ReleaseResource( (Handle)sortPict);
- DisposeGWorld( sortGWorld);
- return false;
- }
-
- MakeSortData();
-
- return true; // YES!! The everything worked out!
- }
-
- Boolean SortPicts::LoadPicture( ConstStr255Param pictName)
- {
- sortPict = (PicHandle)GetNamedResource( 'PICT', pictName);
-
- if( sortPict == nil)
- return false;
-
- sortRect = (*sortPict)->picFrame;
- pictWidth = sortRect.right - sortRect.left;
- pictHeight = sortRect.bottom - sortRect.top;
-
- SetRect( &sortRect, 0, 0, pictWidth, pictHeight);
- copyBitsRect = sortRect;
- windPictRect = sortRect;
- windPictRect.top += kWindPictRectVoffset;
- windPictRect.bottom += kWindPictRectVoffset;
-
- return true;
- }
-
-
- Boolean SortPicts::MakeGWorld( void)
- {
- OSErr myOSErr;
- GWorldPtr tempSortGWorld;
- GDHandle oldGDevice;
- CGrafPtr oldGWorld;
- Rect tempSortRect;
-
- tempSortRect = sortRect;
-
- GetGWorld( &oldGWorld, &oldGDevice);
-
- myOSErr = NewGWorld( &tempSortGWorld, 8, &tempSortRect,
- (CTabHandle) 0, (GDHandle) 0, keepLocal);
-
- if( myOSErr != noErr)
- return false;
-
- sortGWorld = tempSortGWorld;
-
- SetGWorld( sortGWorld, (GDHandle)0);
-
- EraseRect( &sortRect);
- DrawPicture( sortPict, &sortRect);
-
- SetGWorld( oldGWorld, oldGDevice);
-
- return true;
- }
-
-
- Boolean SortPicts::AllocSortData( void)
- {
- sortPixmap = GetGWorldPixMap( sortGWorld);
-
- pictRowBytes = (*sortPixmap)->rowBytes & 0x3FFF;
-
- N = pictWidth * pictHeight;
-
- sortHandle = (SortDataHandle) NewHandle( N * sizeof(long) );
-
- if( sortHandle == nil)
- return false;
-
- return true;
- }
-
-
- void SortPicts::MakeSortData( void)
- {
- long horiz;
- long loop;
- SortPixel pixel;
-
- UseSortData();
-
- horiz = 0;
-
- for( loop = 0; loop < N; ++loop)
- {
- pixel = sortPixels[horiz];
- sortData[loop] = ((SortData) pixel) | (loop << 8);
-
- if( ++horiz == pictWidth)
- {
- horiz = 0;
- sortPixels += pictRowBytes;
- }
- }
-
- UnuseSortData();
- }
-
-
-